const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyPlugin = require("copy-webpack-plugin")
const { CleanWebpackPlugin } = require('clean-webpack-plugin')

module.exports = {
    // 指定模式， 开发模式状态下不进行文件的压缩
    mode: 'development',
    // 指定处理的js文件
    entry: {
        // 将生成的文件放在js文件夹中
        'js/app': './src/main.js'
    },
    // 指定输出的配置
    output: {
        path: path.join(__dirname, "./dist"),
        filename: '[name].js'
    },
    module: {
        rules: [{
            test: /\.art$/,
            use: {
                loader: 'art-template-loader',
                options: {
                    escape: false
                }
            }
        }, {
            test: /\.css$/,
            use: ["style-loader", "css-loader"],
        }]
    },
    // 指定使用的插件
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, './public/index.html'), // 把要托管的html文件作为模板， 复制一份托管到内存中
            filename: 'index.html' // 指定将来在内存中复制出来的页面， 名称为 index.html
        }),
        new CopyPlugin({
            patterns: [
                { from: "./public/*.ico", to: path.join(__dirname, './dist/favicon.ico') },
                { from: "./public/libs", to: path.join(__dirname, './dist/libs') }
            ],
        }),
        new CleanWebpackPlugin()
    ],
    // 开启开发服务的配置
    devServer: {
        contentBase: path.join(__dirname, "./dist"),
        compress: false,
        port: 80,
        proxy: {
            '/api': 'http://localhost:8080',
        },
    },
}